package auction.chapter16.test;

import java.math.BigDecimal;

import org.testng.annotations.Test;

import auction.chapter16.BusinessException;
import auction.model.Bid;
import auction.model.Item;
import auction.model.User;

public class AuctionLogic {
	
	@Test(groups="logic")
	public void highestBidWins() throws BusinessException{
		User user = new User();
		Item auction = new Item();
		BigDecimal bidAmt=new BigDecimal("100.00");
		Bid maxBid=auction.placeBid(user, bidAmt, new Bid(), new Bid());
		
		BigDecimal higherBidAmount=new BigDecimal("91.00");
		auction.placeBid(user, higherBidAmount, maxBid, new Bid());
		
		assert auction.getBids().size() == 2;
		
	}
	
	@Test(groups="logic",expectedExceptions={BusinessException.class})
	public void checkBusinessException() throws BusinessException{
		User user = new User();
		Item auction = new Item();
		BigDecimal bidAmount=new BigDecimal("100.00");
		
		Bid maxBid=new Bid();
		maxBid.setAmount(new BigDecimal("200.00"));
		auction.placeBid(user, bidAmount, maxBid, new Bid());
	}
}
